<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="app">
   

    <p>
      <label><input @change="handleLikesChange" :checked="likes.includes('唱')" type="checkbox" value="唱">唱</label>
      <label><input @change="handleLikesChange" :checked="likes.includes('跳')" type="checkbox" value="跳">跳</label>
      <label><input @change="handleLikesChange" :checked="likes.includes('rap')" type="checkbox" value="rap">rap</label>
      <label><input @change="handleLikesChange" :checked="likes.includes('篮球')" type="checkbox" value="篮球">篮球</label>
    </p>
    {{likes}}
    
  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        likes: ['唱']
      },
      methods: {
        handleLikesChange (e) {
          const value = e.target.value
          console.log(value)
          // 判断likes里是否包含value，如果包含，从likes里把这条数据删除
          if (this.likes.includes(value)) {
            this.likes = this.likes.filter(like => like !== value)
          } else {
            // likes不包含当前value，说明目前没有选中，把value push到likes里
            this.likes.push(value)
          }
        }
      }
    })
  </script>
</body>
</html>
